<?php

class Engine_Controller_Plugin_FinalFilter extends Zend_Controller_Plugin_Abstract {
	
	public function __construct(Array $options = array()) {
		return $this->init($options);
	}
		
	public function init(array $options) {  
		return $this;
	}
	
	public function dispatchLoopShutdown() {
		$xhtml = $this->_response->getBody();
		$xhtml = $this->filter($xhtml);
		$this->_response->setBody($xhtml);
	}

    public function filter($value)
    {
 		$match = array( "[[baseUrl]]", 	
 						"[[imagesUrl]]", 
 						"[[requestUrl]]",
 						"[[layoutUrl]]"
 		);
		$replace   = array(	Zend_Registry::get('baseUrl'),
							Zend_Registry::get('baseUrl')."/public/media/images", 
							Zend_Registry::get('baseUrl').$_SERVER['REQUEST_URI'],
							Zend_Registry::get('layoutUrl')
		);
		$valueFiltered = str_replace($match, $replace, $value);   	
 
        return $valueFiltered;
    }
}
?>